package ru.classbase.dbdumper.model

import java.io.InputStream
import java.io.Writer
import java.sql.ResultSet

typealias TableName = String
typealias SchemaName = String
typealias ColumnName = String

data class DbMetaData(
    val database: String,
    val schemas: Map<String, Schema>,
)

data class DumpContext(
    val schema: String,
    val tableName: String,
    val columns: List<Column>,
    val rs: ResultSet,
    val writer: Writer,
)

data class StorageContext(
    val schema: String,
    val tableName: String,
    val input: InputStream,
)

data class Schema(val schemaName: SchemaName, val tables: Map<TableName, Table>)

data class Table(val tableName: TableName, val columns: Map<ColumnName, Column>)

data class Column(val columnName: String, val dataType: String)

data class ColumnRow(
    val schemaName: SchemaName,
    val tableName: TableName,
    val columnName: String,
    val columnDataType: String
)

enum class CompressionType(val ext: String, val mimeType: String) {
    NONE("", ""), GZIP("gzip", "application/gzip"), ZIP("zip", "application/zip")
}

enum class StorageType { DIRECTORY, GDRIVE }

enum class OutputFormat(val ext: String, val mimeType: String) {
    POSTGRES_SQL_INSERT("sql", "application/sql"),
    JSON("json", "application/json"),
    XML("xml", "application/xml"),
    CSV("csv", "text/csv"),
}

enum class DatabaseProduct(val label: String) {
    POSTGRES("PostgreSQL"),
    MYSQL("MySQL"),
    MSSSQL("Microsoft SQL Server");

    companion object {
        fun find(product: String) =
            values().find { it.label == product } ?: throw IllegalArgumentException("Unknown product $product")
    }
}


